package com.ruoyi.patrol.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtCheckAnswer;
import com.ruoyi.patrol.service.IPtCheckAnswerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检查记录填报Controller
 *
 * @author Du
 * @date 2023-11-21
 */
@RestController
@RequestMapping("/patrol/checkAnswer")
public class PtCheckAnswerController extends BaseController {
    @Autowired
    private IPtCheckAnswerService ptCheckAnswerService;

    /**
     * 查询检查记录填报列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtCheckAnswer ptCheckAnswer) {
        startPage();
        List<PtCheckAnswer> list = ptCheckAnswerService.selectPtCheckAnswerList(ptCheckAnswer);
        return getDataTable(list);
    }

    /**
     * 导出检查记录填报列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:export')")
    @Log(title = "检查记录填报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtCheckAnswer ptCheckAnswer) {
        List<PtCheckAnswer> list = ptCheckAnswerService.selectPtCheckAnswerList(ptCheckAnswer);
        ExcelUtil<PtCheckAnswer> util = new ExcelUtil<PtCheckAnswer>(PtCheckAnswer.class);
        return util.exportExcel(list, "checkAnswer");
    }

    /**
     * 获取检查记录填报详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(ptCheckAnswerService.selectPtCheckAnswerById(id));
    }

    /**
     * 新增检查记录填报
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:add')")
    @Log(title = "检查记录填报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtCheckAnswer ptCheckAnswer) {
        return toAjax(ptCheckAnswerService.insertPtCheckAnswer(ptCheckAnswer));
    }

    /**
     * 修改检查记录填报
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:edit')")
    @Log(title = "检查记录填报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtCheckAnswer ptCheckAnswer) {
        return toAjax(ptCheckAnswerService.updatePtCheckAnswer(ptCheckAnswer));
    }

    /**
     * 修改检查记录填报【批量集合】
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:edit')")
    @Log(title = "检查记录填报", businessType = BusinessType.UPDATE)
    @PutMapping("/app")
    public AjaxResult editAll(@RequestBody List<PtCheckAnswer> answerList) {
        return toAjax(ptCheckAnswerService.updatePtCheckAnswerApp(answerList));
    }

    /**
     * 删除检查记录填报
     */
    @PreAuthorize("@ss.hasPermi('patrol:checkAnswer:remove')")
    @Log(title = "检查记录填报", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ptCheckAnswerService.deletePtCheckAnswerByIds(ids));
    }
}
